require.config({
  baseUrl: "js/vendor",
  paths: {
    "jquery": "jquery-3.4.1.min",
    "bootstrap": "bootstrap.bundle.min",
    "modernizr": "modernizr-3.8.0.min",
  },
  shim: {
    'bootstrap': ['jquery']
  }
});
require(['jquery', 'bootstrap'], function ($) {
  // AMD模块的写法
  function showToast(options) {

    $(".toast").find(".toast-body").text(options.text);
    $(".toast").toast("show", Object.assign({
      delay: 500,
      animation: true,
      autohide: true,
    }, options));
  }

  function checkAgreement() {
    return $("#website-provicy").prop("checked");
  }

  $(function () {
    $("body").delegate("a", 'click', function (e) {
      let link = $(this).attr("href");
      if (link === "" || link === "#") {
        e.preventDefault();
        alert("还没有设置链接！")
      }
    });

    $("span.icon").click(function(event) {
      event.preventDefault();
      event.stopPropagation();
      $(this).next('.child-content').toggle();
      if ($(this).next('.child-content').css("display") === "block") {
        $(this).css({"transform":"rotate(180deg)"});
      }else {
        $(this).css({"transform":"rotate(0)"});
      }
    });
    //    登录事件
    $("#wechatbtn").click(function () {
      const check = checkAgreement()
      if (!check) {
        showToast({
          text: "请同意协议！",
          delay: 3000,
        })
        return false
      }
      $(this).parents(".login-wrapper").hide();
      $("#loginModalLabel").addClass("login-return").html(`<span id="return_login-wrapper"><svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
           <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
         </svg></span>微信登录`);
      $(".more-login").hide();
      $(".wechat-qrcode").show();
    });
    $("#mobile-login").click(function (e) {
      const check = checkAgreement()
      if (!check) {
        showToast({
          text: "请同意协议！",
          delay: 3000,
        })
        return false
      }

      $(".login-wrapper").hide();
      $(".login-form").show();
      $("#loginModalLabel").addClass("login-return").html(`<span id="return_login-wrapper"><svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
           <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
         </svg></span>手机或邮箱登录`);
    });
    $(".other-login span.other-more").click(function () {
      const check = checkAgreement()
      if (!check) {
        showToast({
          text: "请同意协议！",
          delay: 3000,
        })
        return false
      }
      $(".more-login").show().siblings().hide();
      $("#loginModalLabel").addClass("login-return").html(`<span id="return_login-wrapper"><svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
           <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
         </svg></span>更多登录方式`);

    });

    $(".register_account_btn").click(function (e) {
      e.stopPropagation();
      e.preventDefault();
      $("#loginModalLabel").addClass("login-return").html(`<span id="return_login-wrapper"><svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
          <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
        </svg></span>注册账号`);
      $(".register-account").show().siblings().hide();
    })
    $(".forget_password_btn").click(function (e) {
      e.stopPropagation();
      e.preventDefault();
      $("#loginModalLabel").addClass("login-return").html(`<span id="return_login-wrapper"><svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
           <path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
         </svg></span>忘记密码`);
      $(".forget-password").show().siblings().hide();
    })
    $(document).delegate(".login-return", "click", function (e) {
      $("#loginModalLabel").html("账号登录");
      $(".login-wrapper").show().siblings().hide();
    });

    //表单验证
    // 登录
    $("button[type=submit].login-btn").click(function (event) {
      if (!$('input[name=account]').val()) {
        $(this).parents("form").find(".invalid-feedback").show().text('请填写手机或者邮箱');
        event.preventDefault();
        event.stopPropagation();
        return false;
      } else if (!$('input[name=password]').val()) {
        $(this).parents("form").find(".invalid-feedback").show().text('请填写密码');
        event.preventDefault();
        event.stopPropagation();
        return false;
      } else {
        $("#loginModal").modal("hide");
        $('#loginModal').on('hidden.bs.modal', function (e) {
          showToast();
        });
      }
    });
    $("input,textarea").keydown(function () {
      $(".invalid-feedback").hide();
    });
    $(".show-password").click(function (e) {
      if (!$(this).hasClass("active")) {
        $(this).siblings("input").attr("type", "text");
      } else {
        $(this).siblings("input").attr("type", "password");
      }
      $(this).toggleClass("active");
    })
  });
  require(['plugins'], function (mt) {
    mt.mtWindow("手机号码错误！！");
  });
});
